package com.brayan.webapp.model;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

@Entity
// @NamedQuery(name = "findAllPubs", query = "SELECT p FROM Pub p")
public class PubCategory implements Serializable {

	private static final long serialVersionUID = -7271922017926181308L;

	public PubCategory(){		
	}
	
	public PubCategory(Long id){
		this.id = id;  
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	// Meta
	@Column
	private Calendar dateCreated;
	@Column
	private Calendar dateModified;

	// Content
	@Column(nullable = false)
	private String name;

	/***** EVENT HOOKS *****/

	@PrePersist
	protected void onCreate() {
		dateCreated = Calendar.getInstance();
	}

	@PreUpdate
	protected void onUpdate() {
		dateModified = Calendar.getInstance();
	}

	/***** DATA ****/
	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public boolean equals (Object obj) {
	    if (obj==null) return false;
	    if (!(obj instanceof PubCategory)) return false;
	    PubCategory objectToCheck = (PubCategory)obj;
	    return (this.id.equals(objectToCheck.id));
	}
}
